//
// Created by Administrator on 2021/11/15.
// May Saint Diana bless you!
//
#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    /**
     * 检查八个国王八个方向上第一个碰到的皇后
     * @param queens
     * @param king
     * @return
     */
    vector<vector<int>> queensAttacktheKing(vector<vector<int>> &queens, vector<int> &king) {
        vector<vector<int>> chess(8, vector<int>(8, 0));
        // 摆上皇后
        for (vector<int> &queen:queens) {
            chess[queen[0]][queen[1]] = 1;
        }
        vector<vector<int>> ans;
        // 八个方向的增量
        int dires[9] = {1, 0, 1, 1, -1, 0, -1, -1, 1};
        for (int i = 0; i < 8; ++i) {
            int r = king[0] + dires[i];
            int c = king[1] + dires[i + 1];
            while (r >= 0 and r < 8 and c >= 0 and c < 8) {
                if (chess[r][c] == 1) {
                    ans.push_back({r, c});
                    break;
                }
                r += dires[i];
                c += dires[i + 1];
            }
        }
        return ans;

    }
};

int main() {
    vector<vector<int>> queens{{0, 1},
                               {1, 0},
                               {4, 0},
                               {0, 4},
                               {3, 3},
                               {2, 4}};
    vector<int> king{0, 0};
    Solution solution;
    vector<vector<int>> ans = solution.queensAttacktheKing(queens, king);
    for (const vector<int> &row:ans) {
        for (const int &x:row) {
            cout << x << " ";
        }
        cout << endl;
    }
    return 0;
}


